package com.lt.utils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonUtils {
    private String raw_text = "", domain = "", intent = "", timeWord = "", timeNore = "", contentWord = "", contentNore = "";
    private final String json;
    private JSONArray results = new JSONArray();

    public JsonUtils(String Json) {
        json = Json;
    }

    public void getJsonList() {
        try {

            JSONObject rootObject = new JSONObject(json);
            raw_text = rootObject.getString("raw_text");
            results = rootObject.getJSONArray("results");
            if (results.length() != 0) {
                for (int i = 0; i < results.length(); i++) {
                    JSONObject jsonObject = results.getJSONObject(i);
                    domain = jsonObject.getString("domain");
                    intent = jsonObject.getString("intent");
                    JSONObject slots = jsonObject.getJSONObject("slots");
                    JSONArray user_remind_time = slots.getJSONArray("user_remind_time");
                    if (user_remind_time.length() != 0) {
                        for (int j = 0; j < user_remind_time.length(); j++) {
                            JSONObject timeJson = user_remind_time.getJSONObject(j);
                            timeWord = timeJson.getString("word");
                            timeNore = timeJson.getString("norm");

                        }
                    }
                    JSONArray user_wild_content = slots.getJSONArray("user_wild_content");
                    if (user_wild_content.length() != 0) {
                        for (int j = 0; j < user_wild_content.length(); j++) {
                            JSONObject contentJson = user_wild_content.getJSONObject(j);
                            contentWord = contentJson.getString("word");
                            contentNore = contentJson.getString("norm");
                        }
                    }
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }


    public JSONArray getresultsJSONArray() {
        return results;
    }

    public String getraw_text() {
        return raw_text;
    }

    public String getdomain() {
        return domain;
    }

    public String getintent() {
        return intent;
    }

    public String gettimeWord() {
        return timeWord;
    }

    public String gettimeNore() {
        return timeNore;
    }

    public String getcontentWord() {
        return contentWord;
    }

    public String getcontentNore() {
        return contentNore;
    }


}
